﻿namespace TriangleGames.TrainResEditor
{
    using TriangleGames.TrainRes;
    using System;
    using UnityEngine;

    internal class FsmError
    {
        public FsmStateAction Action;
        public string ErrorString;
        public TriangleGames.TrainRes.Fsm Fsm;
        public UnityEngine.GameObject GameObject;
        public System.Type ObjectType;
        public string Parameter;
        public bool RuntimeError;
        public FsmState State;
        public FsmTransition Transition;
        public ErrorType Type;

        public FsmError()
        {
        }

        public FsmError(FsmState state, FsmStateAction action, string errorString)
        {
            this.Action = action;
            this.State = state;
            this.Fsm = state.Fsm;
            this.ErrorString = errorString;
        }

        public FsmError(FsmState state, FsmTransition transition, string errorString)
        {
            this.State = state;
            this.Fsm = state.Fsm;
            this.Transition = transition;
            this.ErrorString = errorString;
        }

        public FsmError(FsmState state, FsmStateAction action, string parameter, string errorString)
        {
            this.Action = action;
            this.Parameter = parameter;
            this.State = state;
            this.Fsm = state.Fsm;
            this.ErrorString = errorString;
        }

        public bool SameAs(FsmError error)
        {
            if (error == null)
            {
                return false;
            }
            if (this.Fsm != error.Fsm)
            {
                return false;
            }
            if (this.State != error.State)
            {
                return false;
            }
            if (this.Action != error.Action)
            {
                return false;
            }
            if (this.Parameter != error.Parameter)
            {
                return false;
            }
            if (this.Transition != error.Transition)
            {
                return false;
            }
            if (this.ErrorString != error.ErrorString)
            {
                return false;
            }
            if (this.Type != error.Type)
            {
                return false;
            }
            if (this.ObjectType != error.ObjectType)
            {
                return false;
            }
            return true;
        }

        public override string ToString()
        {
            string fullFsmLabel = FsmEditorUtility.GetFullFsmLabel(this.Fsm);
            if (this.State != null)
            {
                fullFsmLabel = fullFsmLabel + " : " + this.State.Name;
            }
            if (this.Action != null)
            {
                fullFsmLabel = fullFsmLabel + " : " + FsmEditorUtility.StripNamespace(this.Action.ToString());
            }
            if (this.Parameter != null)
            {
                fullFsmLabel = fullFsmLabel + " : " + this.Parameter;
            }
            return fullFsmLabel;
        }

        public enum ErrorType
        {
            general,
            missingRequiredComponent,
            requiredField
        }
    }
}

